package com.example.mvplibrary.mvplibrary.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import java.util.List;

//Recyclerview.Adapter多布局适配器的抽取
public abstract class MultipleAdapter<DATA> extends BaseAdapter<DATA> {

    private CommType<DATA> commType;
    protected int type = -1;

    public MultipleAdapter(List<DATA> datas, Context context, CommType<DATA> commType) {
        super(datas, context, 0);
        this.commType=commType;
    }

    @Override
    public int getItemViewType(int position) {
        type=commType.getType(position,datas.get(position));
        return type;
    }

    @NonNull
    @Override
    public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        int typeLayout = commType.getTypeLayout(viewType);
        return new BaseViewHolder(layoutInflater.inflate(typeLayout,parent,false));
    }
}
